package com.ror.java.se.collection.set;

import java.util.Iterator;
import java.util.TreeSet;

public class Demo03IntegerTreeSet {
    public static void main(String[] args) {
        TreeSet<Integer> ts = new TreeSet<>();
        ts.add(2);
        ts.add(1);
        ts.add(3);

        //可排序：按照元素的默认规则（从小到大）自动排序。
        System.out.println(ts); //[1, 2, 3]

        System.out.println("==============");

        //迭代器遍历
        Iterator<Integer> it = ts.iterator();
        while (it.hasNext()) {
            Integer i = it.next();
            System.out.print(i + " ");
        }
        System.out.println();

        System.out.println("==============");

        //增强for遍历
        for (Integer t : ts) {
            System.out.print(t + " ");
        }
        System.out.println();

        System.out.println("==============");

        //lambda遍历
        ts.forEach(i -> System.out.print(i + " "));
        System.out.println();
    }
}
